<template>
  <div class="brand">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <transition name="fade-right" mode="out-in">
          <XtxBreadItem>品牌列表</XtxBreadItem>
        </transition>
      </XtxBread>
      <!-- 筛选区 -->
      <BrandFilter />
      <!-- 内容面板 -->
      <div></div>
      <div class="content-panel">
        <BrandPanel :title="brandItem.firstWord.toUpperCase()" v-for="brandItem in BrandList" :key="brandItem">
          <ul>
            <li v-for="brand in brandItem.brands" :key="brand.id">
              <RouterLink :to="`/brand/brand-detail/${brand.id}`">
                <div class="brand-item" :style="{ backgroundImage:'url('+ brand.brandImage +')' }">
                  <div class="box">
                    <div class="head">
                      <i class="iconfont icon-dingwei"></i>
                      <span>{{brand.productionPlace}}</span>
                    </div>
                    <div class="body">
                      <!-- 如果品牌logo不为空，就显示品牌logo，否则就显示默认logo -->
                      <img :src="brand.logo !== null ? brand.logo : require('@/assets/images/logo.png')" alt="">
                    </div>
                    <p class="name-chn">{{brand.name}}</p>
                    <p class="name-en">{{brand.nameEn}}</p>
                    <p class="ellipsis">{{brand.slogan}}</p>
                  </div>
                  <div class="story-box">
                    <h3>品牌故事</h3>
                    <p>{{brand.brandStory === null ? '没有相关品牌故事描述' : brand.brandStory}}</p>
                  </div>
                </div>
              </RouterLink>
            </li>
          </ul>
        </BrandPanel>
      </div>
    </div>
  </div>
</template>

<script>
import BrandFilter from './components/brand-filter.vue'
import BrandPanel from './components/brand-panel.vue'
import { findBrandList } from '@/api/brand'
import { ref } from 'vue'
export default {
  name: 'BrandIndex',
  components: {
    BrandFilter,
    BrandPanel
  },
  setup () {
    const BrandList = ref({})
    findBrandList().then(data => {
      BrandList.value = data.result
    })
    return { BrandList }
  }
}
</script>

<style lang="less" scoped>
.content-panel {
  background: #fff;
  margin-top: 20px;
  h4 {
    font-weight: 400;
    font-size: 30px;
    line-height: 1;
    padding: 0 0 20px 10px;
  }
  ul {
    display: flex;
    flex-wrap: wrap;
    li {
      width: 580px;
      height: 260px;
      margin: 0 20px 15px 20px;
      cursor: pointer;
      .brand-item {
        width: 100%;
        height: 100%;
        background: #ccc no-repeat 50%/cover;
        display: flex;
        align-items: center;
        .box {
          width: 228px;
          height: 196px;
          background: #fff;
          border-radius: 8px;
          margin-left: 50px;
          opacity: .9;
          .head {
            color: #999;
            padding-left: 10px;
            line-height: 50px;
            i & span {
              vertical-align: middle;
            }
          }
          .body {
            width: 180px;
            height: 60px;
            margin: 0 auto;
            img {
              width: 100%;
              height: 100%;
              object-fit: contain;
            }
          }
          p {
            text-align: center;
          }
          .name-chn {
            margin-top: 5px;
          }
          .name-en {
            line-height: 24px;
          }
          .desc {
              color: #666;
            }
        }
        .story-box {
          flex: 1;
          height: 196px;
          padding: 0 20px;
          color: azure;
          h3 {
            line-height: 24px;
            text-align: center;
          }
          p {
            line-height: 20px;
            margin-top: 10px;
          }
        }
      }
    }
  }
}
</style>
